class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int sum = 0;
        int len = nums.length + 1;
        while(right < nums.length){
            //进窗口
            sum += nums[right];
            //判断出窗口
            while(sum >= target){
                //记录结果
                if(len > right - left + 1){
                    len = right - left + 1;
                }
                sum -= nums[left];
                left++;
            }
            right++;
        }
        return len == nums.length + 1 ? 0 : len;
    }
}
